package com.linkhub.oms.common.util;

import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;

/**
 * @ClassName PhoneNumberFormatUtil
 * @Description: com.linkhub.oms.common.util
 * @Author: Jaycle
 * @CreateDate: 2025/5/20 15:58
 * @Version: 1.0
 */
public class PhoneNumberFormatUtil {
    public static boolean isValidPhone(String countryCode, String phoneNumber) {
        try {
            // 只校验中国号码
            if (!countryCode.equals("86")) {
                return true;
            }
            PhoneNumberUtil util = PhoneNumberUtil.getInstance();
            String fullNumber = "+" + countryCode + phoneNumber;
            Phonenumber.PhoneNumber number = util.parse(fullNumber, null);
            return util.isValidNumber(number);
        } catch (Exception e) {
            return false;
        }
    }
}
